﻿using InnoWeb.CEND.BL.Infrastructure;
using InnoWeb.CEND.Core.Model.News;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnoWeb.CEND.BL.Service.News
{
    public class NewsItemService : IService<NewsItem>
    {
        private readonly GenericRepository<NewsItem> _newsItemRepository;
        private readonly IUnitOfWork _unitOfWork;

        public NewsItemService(IUnitOfWork unitOfWork, GenericRepository<NewsItem> newsItemRepository)
        {
            this._newsItemRepository = newsItemRepository;
            this._unitOfWork = unitOfWork;
        }

        public IQueryable<NewsItem> GetAllElements()
        {
            return _newsItemRepository.GetAll();
        }

        public NewsItem GetElementById(int id)
        {
            return _newsItemRepository.GetById(id);
        }

        public void CreateElement(NewsItem entity)
        {
            _newsItemRepository.Insert(entity);
        }

        public void UpdateElement(NewsItem entity)
        {
            _newsItemRepository.Update(entity);
        }

        public void DeleteElement(int id)
        {
            _newsItemRepository.Delete(id);
        }

        public void SaveChanges()
        {
            _unitOfWork.SaveChanges();
        }
    }
}
